import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'

@Component({
  selector: 'app-confirm-dialog',
  template: `
    <div mat-dialog-title class="title">
      <mat-icon>error</mat-icon>
      <span>{{title}}:</span>
    </div>
    <div mat-dialog-content class="content">
    
    <span>{{content}}</span>
      
    </div>
    <div mat-dialog-actions>
      <button mat-raised-button type="button" color="warn" (click)="onClick(true)">确定</button>
      <button mat-button mat-dialog-close type="button" (click)="onClick(false)">取消</button>
    </div>
  `,
  styleUrls:['./confirm-dialog.component.scss']
})
export class ConfirmDialogComponent implements OnInit {
  title = '';
  content = '';

  constructor(
    private dialogRef:MatDialogRef<ConfirmDialogComponent>,
    @Inject(MAT_DIALOG_DATA) private data) { }

  ngOnInit() {
    this.title = this.data.title;
    this.content = this.data.content || '您确认删除该项目吗?'
  }

  // 点击关闭  参数发送给调用者
  onClick(result:boolean){
    this.dialogRef.close(result)
  }

}
